<template>
  <div class="center-cmp">
    <div class="cc-header">
      <dv-decoration-1 style="width:200px;height:50px;" />
      <div style="font-size:20px">分行风险预警</div>
      <dv-decoration-1 style="width:200px;height:50px;" />
    </div>
      <div id="map"></div>
        <dv-border-box-13 class="rmc-bottom-container">
          <Bottom-Charts />
        </dv-border-box-13>
  </div>
</template>

<script>
import * as echarts from 'echarts'
import BottomCharts from './BottomCharts'
import axios from 'axios'
export default {
  name: 'CenterCmp',
  components: {
    BottomCharts
  },
  data () {
    return {
    }
  },
  mounted () {
    this.getMap()
  },
  methods: {
    async getMap () {
      const chartDom = document.getElementById('map')
      const mychart = echarts.init(chartDom)
      let options
      const mapJson = await axios.get('https://geo.datav.aliyun.com/areas_v3/bound/100000_full.json')
      const arr = mapJson.data.features.map(item => {
        return { name: item.properties.name, adcode: item.properties.adcode }
      })
      const myData = [{ name: '海门', value: [121.15, 31.89, 90] }, { name: '鄂尔多斯', value: [109.781327, 39.608266, 120] }, { name: '招远', value: [120.38, 37.35, 142] }, { name: '舟山', value: [122.207216, 29.985295, 123] }
      ]
      mychart.showLoading()
      function a (name, map, drill = true) {
        if (drill) {
          mychart.hideLoading()
          echarts.registerMap(name, map)
          options = {
            geo: {
              map: name
            },
            // },
            title: {
              text: '中国地图',
              triggerEvent: true,
              left: 'right',
              textStyle: {
                color: '#fff'
              }
            },
            tooltip: {
              trigger: 'item',
              showDelay: 0,
              transitionDuration: 0.2
            },
            grid: {
              left: '3%',
              right: '10%',
              bottom: '3%',
              containLabel: true
            },
            visualMap: {
              type: 'continuous',
              left: 'right',
              min: 800,
              max: 50000,
              textStyle: {
                color: '#fff'
              },
              inRange: {
                color: [
                  '#313965',
                  '#4575b4',
                  '#74add1',
                  '#abd9e9',
                  '#e0f3f8',
                  '#ffffbf',
                  '#fee090',
                  '#fdae61',
                  '#f46d43',
                  '#d73027',
                  '#a50026'
                ]
              },
              text: ['High', 'Low'],
              calucable: true
            },
            toolbox: {
              show: true,
              left: 'left',
              top: 'top',
              emphasis: {
                iconStyle: {
                  borderColor: '#fff',
                  textFill: '#fff'
                }
              },
              feature: {
                dataView: { readOnly: true },
                restore: {},
                saveAsImage: {}
              }
            },
            series: [
              {
                name: '中国地图',
                type: 'scatter',
                coordinateSystem: 'geo',
                encode: {
                  tooltip: 2
                },
                map: name,
                emphasis: {
                  label: {
                    show: true
                  }
                },
                zoom: 1.2,
                data: myData
              }
            ]
          }
          mychart.setOption(options)
        }
      }
      a('中国地图', mapJson.data)
      mychart.on('click', async (data) => {
        const { name } = data
        const arrName = arr.map(e => e.name)
        if (arrName.indexOf(name) > -1) {
          const adcode = arr.find((item) => item.name === name).adcode
          console.log('adcode', adcode)
          const map = await axios.get(`https://geo.datav.aliyun.com/areas_v3/bound/${adcode}_full.json`)
          console.log(map)
          a(name, map.data, arrName.indexOf(name) > -1)
        } else {
          a('中国地图', mapJson.data)
        }
      })
    }
  }
}
</script>

<style lang="less">
#map{
  width: 100%;
  height: 100%;
}
.center-cmp {
  width: 100%;
  height: 100%;
  margin: 0px;
  padding: 0px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;

  .cc-header {
    height: 70px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 30px;
  }
  .rmc-bottom-container {
    height: 45%;
  }

}
</style>
